# Sample races at four all-weather UK race courses between 2006 and 2009 with
# horses aged at least 3 years.

library("RODBC")

ch <- odbcConnect("smartform")

races <- sqlQuery(ch, "
SELECT 
    a.race_id,
    meeting_date,
    course,
    class,
    distance_yards,
    winning_time_secs
FROM
    sample_races a
        INNER JOIN
    historic_races b ON a.race_id = b.race_id
ORDER BY course , class , distance_yards
                  ", stringsAsFactors = F)

runners <- sqlQuery(ch, "
SELECT 
    a.race_id,
    name,
    sire_name,
    finish_position,
    distance_behind_winner,
    starting_price_decimal
FROM
    sample_races a
        INNER JOIN
    historic_runners b ON a.race_id = b.race_id
                    ", stringsAsFactors = F)

odbcClose(ch)
rm(ch)